<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <button onclick="begin()">开始</button>
    <button onclick="end()">结束</button>
    <button onclick="begin1()">lol</button>
    <button id="btn1" onclick="getMsg()">获取验证码</button>
    <script>
        var timer = null;
        function begin () {
            console.log('开始计时');
            timer = null;
            timer = setInterval(function() {
                console.log('滴答滴答');
            }, 1000);
        }
        function end() {
            // 指定要清空的定时器
            clearInterval(timer)
        }
        function begin1() {
            // 倒计时
            var time = 5;
            var timer = setInterval(function(){
                if(time) { // 大于0
                    console.log('敌军还有'+time+'秒到达战场，碾碎他们！');
                    time --
                }else {
                    console.log('全军出击！');
                    // 0秒是清楚定时器
                    clearInterval(timer)
                }
            }, 1000)
        }
        function getMsg() {
            time = 10;
            var btn = document.getElementById('btn1');
            // console.log(btn.innerHTML);
            btn.innerHTML = '获取验证码(9)'
        }
    </script>
</body>
</html>